<template>
  <div class="app-container">
    <el-form class="tl-form" ref="form" :model="model" :rules="rules" label-width="150px" :disabled="disableEditSubmit">
      <el-row>
        <!-- <el-col :span="12">
            <el-form-item label="所属项目编码" prop="projectuucode">
              <el-input v-model="model.projectuucode"></el-input>
            </el-form-item>
          </el-col> -->
        <el-col :span="12">
          <el-form-item label="项目结果" prop="projectresult" :rules="rules.validateRequire">
            <el-select v-model="model.projectresult" filterable clearable>
              <el-option v-for="item in codeModel.successFailureList" :key="item.code" :label="item.name" :value="item.code" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="结果公布时间" prop="resulttime">
            <el-date-picker v-model="model.resulttime" type="datetime" placeholder="结果公布时间" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="结项说明" prop="endinstruction" :rules="rules.validateRequire">
            <el-input v-model="model.endinstruction" type="textarea" maxlength="1000" :rows="3"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="项目目标" prop="projectgoal">
            <el-input v-model="model.projectgoal" type="textarea" maxlength="1000" :rows="3"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="项目成果" prop="projectachievement" :rules="rules.validateRequire">
            <el-input v-model="model.projectachievement" type="textarea" maxlength="1000" :rows="3"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="差异分析" prop="difanalysis" :rules="rules.validateRequire">
            <el-input v-model="model.difanalysis" type="textarea" maxlength="1000" :rows="3"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="经验教训" prop="experience" :rules="rules.validateRequire">
            <el-input v-model="model.experience" type="textarea" maxlength="1000" :rows="4"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer" style="text-align: right;">
      <!-- <el-button :type="disableEditSubmit === false ? 'text' : 'primary'" @click="doCancelEdit">取消</el-button> -->
      <el-button type="primary" @click="doSubmitEdit" :loading="saveLoading" v-if="disableEditSubmit === false">保存</el-button>
    </div>
  </div>
</template>

<script>
/** mixins */
import { mixin_edit } from '@tapui/mixins/mixin_edit'
/** 子组件 */
/** 工具类 */
import { putAction, getAction, postAction, deleteAction } from '@tapui/utils/http'
import { queryDataCode } from 'tap-ui/src/api/dataCode'
/** VUE配置 */
export default {
  mixins: [mixin_edit],
  components: {},
  data() {
    return {
      moduleTitle: '项目复盘会',
      urlPrefix: '/base/cbbPmReplay/',
      url: {
        // 额外的url
        loadByProjectUUcode: '/base/cbbPmReplay/loadByProjectUUcode'
      }
    }
  },
  props: {
    isApproving: {
      default: false,
      type: Boolean
    },
    projectUUCode: {
      default: '',
      type: String
    }
  },
  methods: {
    loaded() {
      // 页面加载完毕执行
    },
    componentData() {
      this.doQueryCode()
      this.queryData()
    },
    // 保存执行暂存逻辑
    doSubmitEdit() {
      this.doEdit()
    },
    // 根据projectUUcode提供编码
    queryData() {
      if (!this.url.loadByProjectUUcode) {
        this.$tap.alert('请设置load地址!', 'warning')
        return
      }
      return getAction(this.url.loadByProjectUUcode, { projectUUCode: this.projectUUCode }).then((res) => {
        if (res.success) {
          this.model = res.result
        } else {
          this.$tap.alert(res.message, 'warning')
        }
      })
    },
    // 审批前保存与前端校验
    beforeApproval(resolve, reject) {
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.saveLoading = true
          putAction(this.url.edit, this.model)
            .then((res) => {
              if (res.success) {
                this.$tap.message(res.message, 'success')
                resolve()
              } else {
                this.$tap.alert(res.message, 'warning')
              }
              this.saveLoading = false
            })
            .catch((err) => {
              this.saveLoading = false
            })
        } else {
          reject()
        }
      })
    }
  }
}
</script>
